﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Honestysoft.Financing.Model;
using Honestysoft.Baseframework.WebUI;
using Honestysoft.Workflow.BusinessFacade;
using Honestysoft.Workflow.Model;

namespace Honestysoft.Financing.WebUI.Module.Project
{
    public partial class ProjectCompleteInfo : BasePage
    {
        protected override void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!IsPostBack)
            {
                BindWF();
                Bind();
            }
        }

        protected string _ProjectSN = empty;
        protected string _ProjectName = empty;
        protected string _ProjectCode = empty;
        protected string _Owner971 = empty;
        protected string _Owner = empty;
        protected string _ztz = empty;
        protected string _czljtz = empty;
        protected string _zbjdwje = empty;

        private const string empty = "<span style='color:red;font-weight:700'>缺少该项数据？</span>";

        private void BindWF()
        {
            btnEdit.Attributes.Add("onclick", "javascript:openDialog('" + Globals.Home + "Module/Project/ProjectEdit.aspx?ID=" + Request.QueryString["ID"] + "&FunctionID="+FunctionID+"',720,600,'修改项目信息');return false;");

            //btnConfirm.Attributes.Add("onclick", "javascript:if(checkRequired()){return doConfirm('" + Request.QueryString["ID"] + "');}else{return false;}");
            //btnViewConfirm.Attributes.Add("onclick", "javascript:doConfirm('" + Request.QueryString["ID"] + "');return false;");

            btnConfirm.Attributes.Add("onclick", "javascript:if(checkRequired()){openDialog('" + Globals.Home + "Module/Project/ProjectConfirm.aspx?ID=" + Request.QueryString["ID"] + "&FunctionID=" + FunctionID + "',560,500,'确认初始化');}return false;");
            btnViewConfirm.Attributes.Add("onclick", "javascript:openDialog('" + Globals.Home + "Module/Project/ProjectConfirm.aspx?ID=" + Request.QueryString["ID"] + "&FunctionID=" + FunctionID + "',560,500,'查看确认意见');return false;");


            //WFButtons1.BillCode = "1001";
            //WFButtons1.BuDataID = Request.QueryString["ID"];
            //WFButtons1.EmployeeID = UserLoginer.LoginUser.ID;
            //WFButtons1.BindWFControl();
        }

        private void Bind()
        {
            string projectId = Request.QueryString["ID"];
            BD_Project project = new Honestysoft.Financing.BusinessLogic.Project(Globals.CurrentConnStringName).GetFullProject(projectId);

            if (project.IsInit)
            {
                btnConfirm.Enabled = false;
            }
            else
            {
                btnViewConfirm.Enabled = false;
            }
            if (!string.IsNullOrEmpty(project.Name))
            {
                _ProjectName = project.Name;
                hidName.Value = "1";
            }
            if (!string.IsNullOrEmpty(project.SN))
            {
                _ProjectSN = project.SN;
                hidSN.Value = "1";
            }
            if (!string.IsNullOrEmpty(project.Code))
            {
                _ProjectCode = project.Code;
                hidCode.Value = "1";
            }
            if (!string.IsNullOrEmpty(project.OwnerName))
            {
                _Owner = project.OwnerName;
                hidOwner.Value = "1";
            }
            if (!string.IsNullOrEmpty(project.Owner971Name))
            {
                _Owner971 = project.Owner971Name;
                hidOwner971.Value = "1";
            }
            if (project.Investment.ToString("0.00") == "0.00")
            {
                _ztz = project.Investment.ToString("0.00") + "&nbsp;&nbsp;[" + empty + "]";
            }
            else
            {
                _ztz = project.Investment.ToString("0.00");
                hidZTZ.Value = "1";
            }
            if (project.FinInvestment.ToString("0.00") == "0.00")
            {
                _czljtz = project.FinInvestment.ToString("0.00") + "&nbsp;&nbsp;[" + empty + "]";
            }
            else
            {
                _czljtz = project.FinInvestment.ToString("0.00");
                hidCZLJTZ.Value = "1";
            }
            if (project.TotalCapitalAmount.ToString("0.00") == "0.00")
            {
                _zbjdwje = project.TotalCapitalAmount.ToString("0.00") + "&nbsp;&nbsp;[" + empty + "]";
            }
            else
            {
                _zbjdwje = project.TotalCapitalAmount.ToString("0.00");
                hidZBJDWJE.Value = "1";
            }
            
            rptBudget.DataSource = project.Budgets;
            rptBudget.DataBind();

            if (project.GKLoanAmounts != null && project.GKLoanAmounts.Count > 0) { hidGKLoadAmount.Value = "1"; }
            rptGKAmount.DataSource = project.GKLoanAmounts;
            rptGKAmount.DataBind();

            if (project.LoanAmounts != null && project.LoanAmounts.Count > 0) { hidProjLoadAmount.Value = "1"; }
            rptProjAmount.DataSource = project.LoanAmounts;
            rptProjAmount.DataBind();

            rptXZZBJ.DataSource = project.AddInvesments;
            rptXZZBJ.DataBind();

            if (project.YearPlans != null && project.YearPlans.Count > 0) { hidYearPlan.Value = "1"; }
            rptYearPlan.DataSource = project.YearPlans;
            rptYearPlan.DataBind();
        }


        protected string GetBudgetButtonScript(string dataId)
        {
            return ScriptHelper.LinkButton.GetGridViewButton(Globals.Home + "Module/Project/BD_ProjectBudget_View.aspx", "查看项目概算变动", 400, 370, dataId, FunctionID);
        }

        protected string GetYearPlanButtonScript(string dataId)
        {
            return ScriptHelper.LinkButton.GetGridViewButton(Globals.Home + "Module/Project/BD_ProjectInvestmentPlan_View.aspx", "查看项目投资计划",400, 370, dataId, FunctionID);
        }

        protected string GetProjAmountButtonScript(string dataId)
        {
            return ScriptHelper.LinkButton.GetGridViewButton(Globals.Home + "Module/Project/BD_ProjectLoanAmount_View.aspx", "查看项目贷款额度",400,370, dataId, FunctionID);
        }

        protected string GetGKAmountButtonScript(string dataId)
        {
            return ScriptHelper.LinkButton.GetGridViewButton(Globals.Home + "Module/Project/BD_ProjectGKLoanAmount_View.aspx", "查看项目贷款额度", 400, 370, dataId, FunctionID);
        }

        protected string GetAddAmountButtonScript(string dataId)
        {
            return ScriptHelper.LinkButton.GetGridViewButton(Globals.Home + "Module/Project/BD_ProjectAddInvestment_View.aspx", "查看项目新增资本金", 400,370, dataId, FunctionID);
        }

        //protected void btnConfirm_Click(object sender, EventArgs e)
        //{
        //    WFApply.Drive IDrive = new WFApply.Drive();
        //    WFReturn ret = IDrive.DoStart(UserLoginer.LoginUser.ID, "1001", Request.QueryString["ID"]);
        //    Response.Write(ret.IsSuccess);
        //}
    }
}